
package graphics3d;

import java.awt.Component;
import java.awt.Graphics;


public class Scene extends Component {
    
    private Object3d[] objects;
    private int numberOfObjects = 0;
    
    private int frameWidth;
    private int frameHeight;
    private int L, R, B, T;
    
    private double zCamera;
    
    public Scene(int frameWidth, int frameHeight, int L, int R, int B, int T) {
        this.frameWidth = frameWidth;
        this.frameHeight = frameHeight;
        this.L = L;
        this.R = R;
        this.B = B;
        this.T = T;
    }
    
    public void add(Object3d object) {
        Object3d[] temp = new Object3d[++numberOfObjects];
        for (int i = 0; i < numberOfObjects-1; i++)
            temp[i] = objects[i];
        temp[numberOfObjects-1] = object;
        this.objects = temp;
    }
    public void add(Camera camera) {
        this.zCamera = camera.getzCamera();
    }

    @Override
    public void paint(Graphics g) {
        for (int i = 0; i < numberOfObjects; i++) {
            objects[i].draw(g, frameWidth, frameHeight, L, R, B, T, zCamera);
        }
    }
    
    public void delete(int n) {
        if (n >= numberOfObjects)
            throw new IndexOutOfBoundsException("Сцена содержит " 
                    + numberOfObjects + "объектов\n"
                    + "Невозможно удалить элемент с индексом " + n);
	Object3d[] temp = new Object3d[--numberOfObjects];
	for (int i = 0; i < n; i++)
            temp[i] = objects[i];
	for(int i = n+1; i < numberOfObjects; i++)
            temp[i] = objects[i+1];
	objects = temp;
    }
    
    public void clear() {
        numberOfObjects = 0;
        objects = null;
    }
}
